package com.zbkj.crmeb.merchant.admin.controller;

import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.express.model.ShippingTemplates;
import com.zbkj.crmeb.express.request.ShippingTemplatesRequest;
import com.zbkj.crmeb.express.request.ShippingTemplatesSearchRequest;
import com.zbkj.crmeb.express.service.ShippingTemplatesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "设置 -- 物流 -- 模板")
@RequestMapping("api/admin/mer/express/shipping/templates")
public class MerShippingTemplatesController extends AdminBaseController {

    @Autowired
    private ShippingTemplatesService shippingTemplatesService;

    /**
     * 功能描述: 商户新增物流模板
     * @Param: [request, servletRequest]
     * @Return: com.crmeb.core.common.CommonResult<java.lang.Boolean>
     * @Author: wangzh
     * @Date: 2022/12/29 17:37
     */
    @ApiOperation(value = "商户物流模板新增")
    @PostMapping("/save")
    public CommonResult<Boolean> save(@RequestBody @Validated ShippingTemplatesRequest request, HttpServletRequest servletRequest){
        return CommonResult.success(shippingTemplatesService.create(request, getMerId(servletRequest)));
    }

    /**
     * 功能描述: 获取物流模板
     * @Param: [request, pageParamRequest, servletRequest]
     * @Return: com.crmeb.core.common.CommonResult<com.common.CommonPage<com.zbkj.crmeb.express.model.ShippingTemplates>>
     * @Author: wangzh
     * @Date: 2022/12/29 17:41
     */
    @ApiOperation(value = "商户物流模板分页列表")
    @GetMapping("/list")
    public CommonResult<CommonPage<ShippingTemplates>> getList(@Validated ShippingTemplatesSearchRequest request, @Validated PageParamRequest pageParamRequest, HttpServletRequest servletRequest){
        CommonPage<ShippingTemplates> shippingTemplatesCommonPage = CommonPage.restPage(shippingTemplatesService.getList(request, pageParamRequest, getMerId(servletRequest)));
        return CommonResult.success(shippingTemplatesCommonPage);
    }

    /**
     * 功能描述: 删除
     * @Param: [id]
     * @Return: com.crmeb.core.common.CommonResult<java.lang.String>
     * @Author: wangzh
     * @Date: 2022/12/29 17:42
     */
    @ApiOperation(value = "商户物流模板删除")
    @DeleteMapping("/delete/{id}")
    public CommonResult<String> delete(@PathVariable Integer id){
        if(shippingTemplatesService.remove(id)){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }
    }

    /**
     * 功能描述: 修改
     * @Param: [id, request]
     * @Return: com.crmeb.core.common.CommonResult<java.lang.String>
     * @Author: wangzh
     * @Date: 2022/12/29 17:45
     */
    @ApiOperation(value = "商户物流模板修改")
    @PostMapping("/update")
    public CommonResult<String> update(@RequestParam Integer id, @RequestBody @Validated ShippingTemplatesRequest request){
        shippingTemplatesService.update(id, request);
        return CommonResult.success();
    }

    /**
     * 功能描述: 查询信息
     * @Param: [id]
     * @Return: com.crmeb.core.common.CommonResult<com.zbkj.crmeb.express.model.ShippingTemplates>
     * @Author: wangzh
     * @Date: 2022/12/29 17:46
     */
    @ApiOperation(value = "商户物流模板详情")
    @GetMapping("/info/{id}")
    public CommonResult<ShippingTemplates> info(@PathVariable Integer id){
        return CommonResult.success(shippingTemplatesService.getById(id));
    }

}
